const collectService = require('../services/collectService');
const { successResponse } = require('../utils/errorResponse');
const { formattedArticles } = require('../utils/common');

const collectController = {
  getCollectList: async (req, res, next) => {
    try {
      const collectList = await collectService.getCollectList();
      const formatteCollectList = formattedArticles(collectList, 'created_at');
      successResponse(res, formatteCollectList)
    } catch (error) {
      next(error);
    }
  },
  createCollect: async (req, res, next) => {
    try {
      const result = await collectService.createCollect(req.body);
      successResponse(res, result)
    } catch (error) {
      next(error);
    }
  },
  deleteCollect: async (req, res, next) => {
    try {
      const result = await collectService.deleteCollect(req.body);
      successResponse(res, result)
    } catch (error) {
      next(error);
    }
  },
  updateCollect: async (req, res, next) => {
    try {
      const result = await collectService.updateCollect(req.body);
      successResponse(res, result)
    } catch (error) {
      next(error);
    }
  }
}

module.exports = collectController